package com.xyc.servlet.song;

import com.xyc.mapper.SongMapper;
import lombok.SneakyThrows;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@WebServlet("/deleteSong")
public class DelSongServlet extends HttpServlet {
    @SneakyThrows
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id_delete");

        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        SongMapper songMapper = ctx.getBean("songMapper", SongMapper.class);
        songMapper.deleteSong(id);
        req.getRequestDispatcher("mySong").forward(req, resp);
    }
}
